package com.ruoyi.web.controller.qsng;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.qsng.domain.KShopBanner;
import com.ruoyi.qsng.service.IKShopBannerService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商城轮播Controller
 * 
 * @author gk
 * @date 2023-07-13
 */
@RestController
@RequestMapping("/system/banner")
public class KShopBannerController extends BaseController
{
    @Autowired
    private IKShopBannerService kShopBannerService;

    /**
     * 查询商城轮播列表
     */
    @PreAuthorize("@ss.hasPermi('system:banner:list')")
    @GetMapping("/list")
    public TableDataInfo list(KShopBanner kShopBanner)
    {
        startPage();
        List<KShopBanner> list = kShopBannerService.selectKShopBannerList(kShopBanner);
        return getDataTable(list);
    }

    /**
     * 导出商城轮播列表
     */
    @PreAuthorize("@ss.hasPermi('system:banner:export')")
    @Log(title = "商城轮播", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KShopBanner kShopBanner)
    {
        List<KShopBanner> list = kShopBannerService.selectKShopBannerList(kShopBanner);
        ExcelUtil<KShopBanner> util = new ExcelUtil<KShopBanner>(KShopBanner.class);
        util.exportExcel(response, list, "商城轮播数据");
    }

    /**
     * 获取商城轮播详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:banner:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(kShopBannerService.selectKShopBannerById(id));
    }

    /**
     * 新增商城轮播
     */
    @PreAuthorize("@ss.hasPermi('system:banner:add')")
    @Log(title = "商城轮播", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KShopBanner kShopBanner)
    {
        return toAjax(kShopBannerService.insertKShopBanner(kShopBanner));
    }

    /**
     * 修改商城轮播
     */
    @PreAuthorize("@ss.hasPermi('system:banner:edit')")
    @Log(title = "商城轮播", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KShopBanner kShopBanner)
    {
        return toAjax(kShopBannerService.updateKShopBanner(kShopBanner));
    }

    /**
     * 删除商城轮播
     */
    @PreAuthorize("@ss.hasPermi('system:banner:remove')")
    @Log(title = "商城轮播", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(kShopBannerService.deleteKShopBannerByIds(ids));
    }
}
